<template>
  <div class="manage-box">
    <div class="manage-content">
      <div class="title">机动车停车管理</div>
      <!--echarts图-->
      <div class="main-manage"></div>
      <!--管理分类显示-->
      <div class="manage-legend">
        <div v-for="(item, i) in stopData" :key="i"><span :style="{background: item.color}" ></span><i>{{ item.name}}</i><b>{{item.num}}</b></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'stopManage',
  data () {
    return {
      chart: '',
      stopData: [{ name: '常驻车辆', num: 152, color: '#50E3C2' }, { name: '临停车辆', num: 48, color: '#00A5ED' }, { name: '空闲车位', num: 64, color: '#666' }]// 停车管理类型数据
    }
  },
  props: {
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    },
    option: {
      type: Object,
      default () {
        return {
          tooltip: {
            show: false,
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)'
          },
          // title: {
          //   text: '机动车停车管理',
          //   textStyle: {
          //     color: '#fff',
          //     fontSize: 12,
          //     fontWeight: 'normal'
          //   },
          // },
          series: [
            {
              type: 'pie',
              radius: ['55%', '75%'],
              labelLine: {
                normal: {
                  show: false
                }
              },
              avoidLabelOverlap: false,
              silent: true,
              label: {
                normal: {
                  show: true,
                  position: 'center',
                  // borderRadius: 4,
                  formatter: function (argument) {
                    let html = `264\n总数`
                    return html
                  },
                  textStyle: {
                    fontSize: 16,
                    color: '#50E3C2'
                  },
                  per: {
                    color: '#eee',
                    backgroundColor: '#334455',
                    padding: [2, 4],
                    borderRadius: 2
                  }
                }
              },
              // itemStyle: {
              //   normal: {
              //     borderWidth: 4,
              //     borderColor: '#2B3648',
              //   }
              // },
              hoverAnimation: false,
              center: ['75%', '52%'],
              data: [
                {
                  value: 0,
                  itemStyle: {
                    color: '#50E3C2'
                  }
                },
                {
                  value: 0,
                  itemStyle: {
                    color: '#00A5ED'
                  }
                },
                {
                  value: 0,
                  itemStyle: {
                    color: '#202835'
                  }
                }
              ]
            }
          ]
        }
      }
    }
  },
  mounted () {
    this.getChart()
  },
  methods: {
    getChart () {
      let temp = this.option
      let length = this.stopData.length
      for (let i = length - 1; i >= 0; i--) {
        temp.series[0].data[i].value = this.stopData[i].num
        temp.series[0].data[i].itemStyle.color = this.stopData[i].color
      }
      this.chart = this.$echarts.init(document.getElementsByClassName('main-manage')[0])
      this.chart.setOption(this.option)
    }

  }
}
</script>

<style scoped>
  .manage-box {
    width: 100%;
    margin-bottom: 10px;
  }

  .manage-content {
    background: rgba(43, 54, 72, 0.95);
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    position: relative;
    width: 100%;
    padding: 13px;
    box-sizing: border-box;
  }

  .manage-content .title {
    color: #FFFFFF;
    position: relative;
    top: 10px;
    left: 10px;
  }

  .main-manage {
    height: 130px;
    position: relative;
  }

  .manage-legend {
    height: 70px;
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 55px;
    left: 24px;
  }

  .manage-legend i {
    font-style: normal;
    color: #9FACC3;
    font-size: 12px;
  }

  .manage-legend b {
    float: right;
    font-size: 14px;
    color: #50E3C2;
    font-weight: normal;
  }

  .manage-legend span {
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    width: 8px;
    height: 8px;
    display: inline-block;
    /*float: left;*/
    margin-right: 9px;
  }

  .manage-legend div {
    width: 80%;
    line-height: 30px;
    color: #fff;
    margin-right: 30px;
  }
</style>
